package com.example.crm.servlet;

import com.example.crm.pojo.Customer;
import com.example.crm.service.ICustomerService;
import com.example.crm.service.impl.CustomerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateUser")
public class UpdateCustomerServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        System.out.println("updateUser收到请求");
        long id=Long.parseLong(req.getParameter("cust_id"));
        String name = req.getParameter("cust_name");
        long createId=1000;
        String level = req.getParameter("cust_level");
        String source = req.getParameter("cust_source");
        String linkman = req.getParameter("cust_linkman");
        String phone = req.getParameter("cust_phone");
        String mobile = req.getParameter("cust_mobile");

        Customer customer = new Customer();
        customer.setCustId(id);
        customer.setCustName(name);
        customer.setCustCreateId(createId);
        customer.setCustLevel(level);
        customer.setCustSource(source);
        customer.setCustLinkman(linkman);
        customer.setCustPhone(phone);
        customer.setCustMobile(mobile);

        System.out.println(customer);
        ICustomerService customerService = new CustomerServiceImpl();
        customerService.updateUser(customer);

        resp.sendRedirect("customer");
    }
}
